package com.giant.lsp.processPath;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//import java.util.Arrays;
import java.util.*;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;


@SpringBootApplication
public class ProcessPathApplication {

	public static void main(String[] args) {
		SpringApplication.run(ProcessPathApplication.class, args);
	}


	//@Bean
	public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
		return args -> {

			System.out.println("Let's inspect the beans provided by Spring Boot:");

			String[] beanNames = ctx.getBeanDefinitionNames();
			Arrays.sort(beanNames);
			for (String beanName : beanNames) {
				System.out.println(beanName);
			}

		};
	}

	@Bean
	public CommandLineRunner testDAGPathFinder1(ApplicationContext ctx) {
		return args -> {

			System.out.println("Looking for DAG Path now: ");

			// 示例图的邻接表表示
			Map<String, List<String>> graph = new HashMap<>();
			graph.put("A", Arrays.asList("B", "C"));
			graph.put("B", Arrays.asList("D", "E"));
			graph.put("C", Arrays.asList("F"));
			graph.put("D", Collections.emptyList());
			graph.put("E", Arrays.asList("F"));
			graph.put("F", Collections.emptyList());

			// 源节点和目标节点集合
			String source = "A";
			Set<String> targets = new HashSet<>(Arrays.asList("D", "F"));

			// 创建DAGPathsFinder实例并查找路径
			DAGPathsFinder pathsFinder = new DAGPathsFinder(graph);
			List<List<String>> allPaths = pathsFinder.findAllPathsFromSourceToTargets(source, targets);

			// 打印所有路径
			for (List<String> path : allPaths) {
				System.out.println(path);
			}


		};
	}

}

